/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package co.com.entities;

import java.io.Serializable;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;
import javax.persistence.Basic;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.PostLoad;
import javax.persistence.Table;
import javax.persistence.TableGenerator;

/**
 *
 * @author dloaiza
 */
@Entity
@Table(name = "TAB_ROLES")
@NamedQueries({
    @NamedQuery(name = "Roles.findAll", query = "SELECT r FROM Roles r")})
public class Roles implements Serializable {
    private static final long serialVersionUID = 1L;
    // @Max(value=?)  @Min(value=?)//if you know range of your decimal fields consider using these annotations to enforce field validation
    @TableGenerator(name = "rolGen",
            table = "TBL_SQ",
            pkColumnName = "GEN_KEY",
            valueColumnName = "GEN_VALUE",
            pkColumnValue = "FAC_CON",
            initialValue = 0,
            allocationSize = 1)
    @GeneratedValue(strategy=GenerationType.TABLE, generator="rolGen")
    @Id
    @Basic(optional = false)
    @Column(name = "CDROL", nullable = false, precision = 30, scale = 0)
    private BigDecimal cdrol;
    @Basic(optional = false)
    @Column(name = "DSROL", nullable = false, length = 150)
    private String dsrol;
    @OneToMany(mappedBy = "cdrol", fetch = FetchType.LAZY)
    private List<Usuario> usuarioList;

    public Roles() {
    }

    public Roles(BigDecimal cdrol) {
        this.cdrol = cdrol;
    }

    public Roles(BigDecimal cdrol, String dsrol) {
        this.cdrol = cdrol;
        this.dsrol = dsrol;
    }

    public BigDecimal getCdrol() {
        return cdrol;
    }

    public void setCdrol(BigDecimal cdrol) {
        this.cdrol = cdrol;
    }

    public String getDsrol() {
        return dsrol;
    }

    public void setDsrol(String dsrol) {
        this.dsrol = dsrol;
    }

    public List<Usuario> getUsuarioList() {
        return usuarioList;
    }

    public void setUsuarioList(List<Usuario> usuarioList) {
        this.usuarioList = usuarioList;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (cdrol != null ? cdrol.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Roles)) {
            return false;
        }
        Roles other = (Roles) object;
        if ((this.cdrol == null && other.cdrol != null) || (this.cdrol != null && !this.cdrol.equals(other.cdrol))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "co.com.entities.Roles[ cdrol=" + cdrol + " ]";
    }
    
    @PostLoad
    public void fixIt(){
        this.usuarioList = new ArrayList<Usuario>(this.usuarioList);
    }
}
